﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using MapCenterSystem.DataInfo;
using MapCenterSystem.DefineType;
using MapCenterSystem.Utility;
using MapCenterSytem.Process;
using MobiMap.Guest;
using MobiMap_Service.Models;
using MapHandler = MobiMap_Service.Models.MapHandler;

namespace MobiMap_Service.Controllers
{
    public class MapApiController : ApiController
    {
        MapHandler _mapHandler = new MapHandler();

        // GET api/mapapi
        public IList<HomeInfoEx> GetListAddress(string keyword)
        {
            IList<HomeInfoEx> lstHomeInfo = new List<HomeInfoEx>();
            List<string> lst = StringHelper.GetNumberAndStreet(keyword);
            string area = StringHelper.GetSearchString(lst[1],
                                                       AppDomain.CurrentDomain.BaseDirectory +
                                                       ConfigurationManager.AppSettings["abbr_file"]);
            lstHomeInfo = HomeBUS.FindExactAddress(lst[0], area);
            if (lstHomeInfo.Count == 0)
            {
                lstHomeInfo = HomeBUS.FindNearAddress(StringHelper.GetExactNumber(lst[0]), area);
            }
            return lstHomeInfo;
        }

        public IList<PlaceInfo> GetListService(int id, string keyword)
        {
            keyword = StringHelper.GetSearchString(keyword,
                                                   AppDomain.CurrentDomain.BaseDirectory +
                                                   ConfigurationManager.AppSettings["abbr_file"]);
            IList<PlaceInfo> lstPlaceInfo = new List<PlaceInfo>();
            lstPlaceInfo = PlaceEx.GetPlaceByKeyword(keyword);
            return lstPlaceInfo;
        }

        public byte[] GetMapDefault()
        {
            Image img = _mapHandler.GetMapDefault();
            byte[] array = Helper.imageToByteArray(img);
            return array;
        }

        public byte[] GetMyLocation(double latitude, double longitude)
        {
            Image img = _mapHandler.DrawFlagInMap(latitude, longitude);
            byte[] array = Helper.imageToByteArray(img);
            return array;
        }
    }
}
